package dao.Impl;

import dao.UserDao;
import pojo.User;
import utlis.DaoUtils;

import java.sql.SQLException;
import java.util.Collections;
import java.util.List;

public class UserDaoImpl implements UserDao {
    @Override
    public int insertUser(User user) throws SQLException {
        String sql = "insert into user values (?,?,?)";
        Object[] args = {user.getId(),user.getName(),user.getPassword()};
        return DaoUtils.commonsUpdate(sql,args);
    }

    @Override
    public int deleteById(Integer id) throws SQLException {
        String sql = "delete from user where id = ?";
        return DaoUtils.commonsUpdate(sql, id);
    }

    @Override
    public int updateUser(User user) throws SQLException {
        String sql = "update user set name = ? , password = ? where id = ?";
        Object[] args = {user.getName(),user.getPassword(),user.getId()};
        return DaoUtils.commonsUpdate(sql,args);
    }

    @Override
    public List<Object> queryAllUser() throws SQLException {
        String sql = "select * from user";
        List<Object> objectList = DaoUtils.commonsQuery(sql, User.class);
        return objectList;
    }

}
